﻿using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace EF6Sample
{
    class Program
    {
        static void Main(string[] args)
        {
            SqlDbContext context = new SqlDbContext();
            ConstructDb();


            //context.Students
            //    .Where(s => s.SleepIn.Location == "")
            //    .Include(s=>s.Teachers.Select(ts=>ts.Salary))
            //    .FirstOrDefault();
            context.Teachers.Where(t => t.Id > 5)
                .Include(t => t.Students.Select(ts => ts.SleepIn))
                .Include(t => t.Students.Select(ts => ts.StudyIn))
                .FirstOrDefault();

            //SqlDbContext context1 = new SqlDbContext();


            //context1.Set<Bed>().Where(b => b.Location == "closure").FirstOrDefault();





            //context.Students.Add(new Student
            //{
            //    //Id = new Guid(),
            //    Name = "lgy",
            //    SleepIn = new Bed { Id = Guid.NewGuid() }
            //});
            ////context.Teachers.Add(new Teacher { Id = new Guid(), Name = "fg" });
            //context.SaveChanges();
            //  Person pfg = context.Persons.Where(p => p.Name == "fg").SingleOrDefault();
            //Student sfg = context.Students.Where(s => s.Name == "lgy").SingleOrDefault();
            //Console.WriteLine(sfg.Id);
            //Student student = context.Students.Find(1);
            //string query = "SELECT * FROM Students WHERE Id=@pId";
            //Student s1 = context.Students.SqlQuery(query, 1).AsNoTracking().SingleOrDefault();

            //Console.WriteLine(student.Name);
        }
        static void ConstructDb()
        {
            SqlDbContext context = new SqlDbContext();
            Database db = context.Database;
            db.Delete();
            db.Create();
        }
    }
}
